package com.itheima.springmvc.exception;

import com.itheima.springmvc.pojo.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author ：sean
 * @date ：Created in 2022/4/16
 * @description ：
 * @version: 1.0
 */
@RestControllerAdvice
@Slf4j
public class HandlerException {

	@ExceptionHandler({
		CustomException.class
	})
	public Result handlerCustomException(CustomException e){
		e.printStackTrace();
		log.error("[业务异常:${}]",e.getMessage());
		return new Result(false,e.getMessage());
	}

	@ExceptionHandler({
		Exception.class
	})
	public Result handlerOtherException(Exception e){
		e.printStackTrace();
		log.error("[非业务异常:${}]",e.getMessage());
		return new Result(false,e.getMessage());
	}
}
